function setValueByPath(targetData: any, key: string, value: string) {
  const pathList = key.split(".");
  let parent = targetData;
  let pathItem = pathList.shift();

  while (pathItem != null) {
    if (pathList.length === 0) {
      parent[pathItem] = value;
    } else {
      if (!parent[pathItem]) {
        if (isNaN(Number(pathList[0]))) {
          parent[pathItem] = {};
        } else {
          parent[pathItem] = [];
        }
      }
      parent = parent[pathItem];
    }
    pathItem = pathList.shift();
  }
}

export const handleJsonStream = (proxyData: any, data: string) => {
  const lines = data.split("\n").slice(-2);
  lines.forEach((line) => {
    const [key, value] = line.split("=");
    if (value) {
      setValueByPath(proxyData, key, value);
    }
  });
    return {...proxyData}
};
